package Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

public class 下一个排列 {
    public void nextPermutation(int[] nums) {
        int i,j,k;
        j=k=nums.length-1;
        i=nums.length-2;

        while (nums[i]>=nums[j]&&i>=0){
            i--;
            j--;
            }
        if(i>=0){
            while (nums[i]>=nums[k]){
                k--;
            }
            int t=nums[i];
            nums[i]=nums[k];
            nums[k]=t;
            Arrays.sort(nums,j,nums.length);
        }else {
            Arrays.sort(nums);
        }

        }

    }

